home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume17 / contest-prog / part02 < prev    next >
Encoding:
Internet Message Format  |  1989-02-06  |  33.5 KB

  1. Subject:  v17i085:  ACM-style programmning contest programs, Part02/03
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: jim nelson <nelson@uncecs.edu>
  6. Posting-number: Volume 17, Issue 85
  7. Archive-name: contest-prog/part02
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line, then unpack
  11. # it by saving it into a file and typing "sh file".  To overwrite existing
  12. # files, type "sh file -c".  You can also feed this as standard input via
  13. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  14. # will see the following message at the end:
  15. #        "End of archive 2 (of 3)."
  16. # Contents:  Makefile chexec8.c compare.c passwd prob1.c prob13.c
  17. #   prob13.txt prob14.c prob14.txt prob15.txt prob16.c prob16.txt
  18. #   prob17.c prob17.txt prob2.txt prob4.txt prob5.txt prob6.txt sb.c
  19. #   start
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'Makefile'\"
  23. else
  24. echo shar: Extracting \"'Makefile'\" \(2655 characters\)
  25. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  26. XCC=cc
  27. XCFLAGS= -s -O
  28. X.IGNORE:
  29. X#a public directory such as /usr/local
  30. XLOCAL=/usr/contest
  31. X#the judges directory
  32. XJUDGES=/usr2/judges
  33. X#the judges group
  34. XGROUP=453
  35. X#where the scoreboard is
  36. X#this really should be a dependecy on a .h file for just score.c
  37. X#but it's really easier just now to :
  38. XSCOREBOARD=\"$(JUDGES)/scoreboard\"
  39. X
  40. X#parallel make flag for sequent only:
  41. X#P=&
  42. X#(only, I guess, sequent people appreciate the & flag)
  43. X#maybe others have a similar thingie ... but I cannot know.
  44. X
  45. X#below here shouldn't need modifying (?)
  46. X
  47. XTBEG=prob1.txt prob2.txt prob3.txt prob4.txt prob5.txt prob6.txt
  48. X#TINT=prob7.txt prob8.txt prob9.txt prob10.txt prob11.txt prob12.txt
  49. XTADV=prob13.txt prob14.txt prob15.txt prob16.txt prob17.txt prob18.txt
  50. XTSRC= $(TBEG) $(TINT) $(TADV) 
  51. X
  52. XCBEG=prob1.c prob2.c prob3.c prob4.c prob5.c prob6.c
  53. X#CINT=prob7.c prob8.c prob9.c prob10.c prob11.c prob12.c
  54. XCADV=prob13.c prob14.c prob15.c prob16.c prob17.c prob18.c
  55. XCSRC= $(CBEG) $(CINT) $(CADV) 
  56. X
  57. XABEG=prob1.ans prob2.ans prob3.ans prob4.ans prob5.ans prob6.ans
  58. X#AINT=prob7.ans prob8.ans prob9.ans prob10.ans prob11.ans prob12.ans
  59. XAADV=prob13.ans prob14.ans prob15.ans prob16.ans prob17.ans prob18.ans
  60. XANS= $(ABEG) $(AINT) $(AADV) 
  61. X
  62. XIBEG=prob1.in prob2.in prob3.in prob4.in prob5.in prob6.in 
  63. X#IINT=prob7.in prob8.in prob9.in prob10.in prob11.in prob12.in
  64. XIADV=prob13.in prob14.in prob15.in prob16.in prob17.in prob18.in
  65. XIN=$(IBEG) $(IINT) $(IADV)
  66. X
  67. XALLC=$(CSRC) compare.c score.c seconds.c chexec8.c syserr.c digits.c \
  68. Xshorten.c sb.c
  69. XOTHER=n passwd start f sf README Makefile gr testem judge visc \
  70. Xshutofflogins scoreascorrect scoreasincorre scoreboard
  71. X
  72. Xall: $(P) chexec8 seconds compare score judge gr shorten digits \
  73. Xtestem
  74. X    chmod +x gr judge testem
  75. X    testem
  76. X
  77. Xinstall:
  78. X    mkdir keep
  79. X    mkdir subdir
  80. X    mkdir $(LOCAL)
  81. X    chmod 777 $(LOCAL)
  82. X    cp seconds $(LOCAL)
  83. X    chmod +rx $(LOCAL)/seconds
  84. X    sed s/GROUP/$(GROUP)/ judge > $(LOCAL)/judge
  85. X    chmod +rx $(LOCAL)/judge
  86. X    cp score $(LOCAL)
  87. X    chmod 755 $(LOCAL)/score
  88. X    chmod u+s $(LOCAL)/score
  89. X
  90. Xshar: $(TSRC) $(ALLC) $(ANS) $(IN) $(OTHER)
  91. X    makekit -m -s30k rules contestrules \
  92. X    $(TSRC) $(ALLC) $(ANS) $(IN) $(OTHER)
  93. X
  94. Xpasswd: shutofflogins
  95. X    shutofflogins
  96. X
  97. Xchexec8: $(P) chexec8.o syserr.o
  98. X    cc -o chexec8 chexec8.o syserr.o
  99. X
  100. Xseconds: seconds.o
  101. X    cc -o seconds seconds.o
  102. X
  103. Xshorten: shorten.o
  104. X    cc -o shorten shorten.o
  105. X
  106. Xcompare: compare.o
  107. X    cc -o compare compare.o
  108. X
  109. Xdigits: digits.o
  110. X    cc -o digits digits.o
  111. X
  112. Xscore: score.o Makefile
  113. X    cc -o score -s score.o
  114. X
  115. Xscore.o: score.c Makefile
  116. X    cc -c -DSCOREBOARD=$(SCOREBOARD) score.c
  117. X
  118. Xscoretime:
  119. X    cp /dev/null scoretime
  120. X
  121. Xsend:
  122. X    uuto Part*  3b2b\!judges
  123. X
  124. Xclean:
  125. X    rm *.e *.o Part* chexec8 seconds compare score digits shorten
  126. X
  127. END_OF_FILE
  128. if test 2655 -ne `wc -c <'Makefile'`; then
  129.     echo shar: \"'Makefile'\" unpacked with wrong size!
  130. fi
  131. # end of 'Makefile'
  132. fi
  133. if test -f 'chexec8.c' -a "${1}" != "-c" ; then 
  134.   echo shar: Will not clobber existing file \"'chexec8.c'\"
  135. else
  136. echo shar: Extracting \"'chexec8.c'\" \(882 characters\)
  137. sed "s/^X//" >'chexec8.c' <<'END_OF_FILE'
  138. X#include <stdio.h>
  139. X/*#include <fcntl.h>*/
  140. X#include <signal.h>
  141. X/*#include <sys/wait.h>*/
  142. Xint k;
  143. Xmain(argc,argv)
  144. Xchar **argv;
  145. X{
  146. X    int childstatus(),oops();
  147. X    setuid(getuid());
  148. X    k=fork();
  149. X    if(k){
  150. X        signal(SIGALRM,oops);
  151. X#ifndef SIGCHLD
  152. X#define SIGCHLD SIGCLD
  153. X#endif
  154. X/*CHLD=20 for dynix, CLD=18 for SysV2*/
  155. X/* anyway what we want is to catch "death of child" signal*/
  156. X        signal(SIGCHLD,childstatus);
  157. X        alarm(10);
  158. X        wait(0);}
  159. X    else
  160. X        execl(argv[1],"dumbo",0);
  161. X}
  162. Xchildstatus(sig,code,x)
  163. X{
  164. X    int i,j,m;
  165. X
  166. X    fprintf(stderr,"sig=%d,code=%d, k=%d\n",sig,code,k);
  167. X
  168. X    for(i=0;i<200;i++){
  169. X        j=k+i;
  170. X        j= j % 32768;
  171. X        if(j>1){
  172. X            m=kill(j,9);
  173. X            if(m>=0)fprintf(stderr,"killed %d ",j);
  174. X            }
  175. X        }
  176. X
  177. X    exit(0);
  178. X}
  179. Xoops(sig,code,x)
  180. X{
  181. X    fprintf(stderr,"sig=%d,code=%d\n",sig,code);
  182. X    fprintf(stderr,"there may be a daemon attack underway\n");
  183. X    fprintf(stderr,"kill %d\n",k);
  184. X    childstatus(sig,code,x);
  185. X    exit(1);
  186. X}
  187. X
  188. END_OF_FILE
  189. if test 882 -ne `wc -c <'chexec8.c'`; then
  190.     echo shar: \"'chexec8.c'\" unpacked with wrong size!
  191. fi
  192. # end of 'chexec8.c'
  193. fi
  194. if test -f 'compare.c' -a "${1}" != "-c" ; then 
  195.   echo shar: Will not clobber existing file \"'compare.c'\"
  196. else
  197. echo shar: Extracting \"'compare.c'\" \(1085 characters\)
  198. sed "s/^X//" >'compare.c' <<'END_OF_FILE'
  199. X#include <stdio.h>
  200. X#define tab '\t'
  201. X#define null '\0'
  202. X#define newline '\n'
  203. Xmain(argc,argv)
  204. Xchar **argv;
  205. X{
  206. X    FILE *fpa, *fpb;
  207. X    char linea[200], lineb[200];
  208. X    char tempa[200], tempb[200];
  209. X
  210. X    char *p, *q;
  211. X    int eofa=0,eofb=0;
  212. X    int compare;
  213. X    if(argc!=3)exit(1);
  214. X
  215. X    fpa=fopen(argv[1],"r");
  216. X    if(fpa==(FILE *)0)exit(2);
  217. X
  218. X    fpb=fopen(argv[2],"r");
  219. X    if(fpb==(FILE *)0)exit(3);
  220. X    eofa=eofb=0;
  221. X    compare=0;
  222. Xread:
  223. X    if(!eofa)if(fgets(linea,199,fpa)!=linea)eofa=1;
  224. X    if(!eofb)if(fgets(lineb,199,fpb)!=lineb)eofb=1;
  225. X    if(eofa && eofb)exit(compare);
  226. X
  227. X    if(eofa&& !eofb)exit(4);
  228. X    if(eofb&& !eofa)exit(5);
  229. X    if(eofa || eofb)exit(6);
  230. X
  231. Xfor(p=linea;*p;p++){if(*p==tab) *p=' ';if(*p==newline) *p=0;}
  232. Xfor(p=lineb;*p;p++){if(*p==tab) *p=' ';if(*p==newline) *p=0;}
  233. X    p=linea;
  234. X    q=lineb;
  235. Xtightloop:
  236. X    while(*p==' ' || *p==tab || *p==newline)p++;
  237. X    while(*q==' ' || *q==tab || *q==newline)q++;
  238. X    if(*p!= *q){
  239. X        printf("them: %s\n",linea);
  240. X        printf("  us: %s\n",lineb);
  241. X        compare=1;
  242. X        puts("------------------------------------");
  243. X        goto read;
  244. X        }
  245. X    else{
  246. X        p++;
  247. X        q++;
  248. X        if(*p==null)if(*q==null)goto read;
  249. X        goto tightloop;
  250. X    }
  251. X
  252. X}
  253. END_OF_FILE
  254. if test 1085 -ne `wc -c <'compare.c'`; then
  255.     echo shar: \"'compare.c'\" unpacked with wrong size!
  256. fi
  257. # end of 'compare.c'
  258. fi
  259. if test -f 'passwd' -a "${1}" != "-c" ; then 
  260.   echo shar: Will not clobber existing file \"'passwd'\"
  261. else
  262. echo shar: Extracting \"'passwd'\" \(1863 characters\)
  263. sed "s/^X//" >'passwd' <<'END_OF_FILE'
  264. Xroot:Jfy5vADKI.PUo:0:0:Admin:/:/bin/csh
  265. Xdaemon:*:1:10:Admin:/:
  266. Xusrlimit:HVhogDpnYyySg:2:2:This is a 32 user system, DO NOT REMOVE THIS LINE:/:/dev/null
  267. Xuucp:LHFftElncpbcU:66:10:uucp owner:/usr/lib/uucp:/bin/csh
  268. X3b2b::67:10:UNIX-to-UNIX Copy:/usr/spool/uucppublic:/usr/lib/uucp/uucico
  269. X3b2a::68:10:UNIX-to-UNIX Copy:/usr/spool/uucppublic:/usr/lib/uucp/uucico
  270. Xlmc::69:10:UNIX-to-UNIX Copy:/usr/spool/uucppublic:/usr/lib/uucp/uucico
  271. Xsigma::71:10:UNIX-to-UNIX Copy:/usr/spool/uucppublic:/usr/lib/uucp/uucico
  272. Xcltsqnt::72:10:sequent:/usr/spool/uucppublic:/usr/lib/uucp/uucico
  273. Xnelson:TQQhhbK575Jtc:100:0:j h nelson,MO-263,3300,3926032/3955570/147.53,:/usr1/nelson:/bin/csh
  274. Xherbst:hwshDCyvtoI.s:104:100:R.T. Herbst,MO 256,3248,2563304,universe(ucb):/usr1/herbst:
  275. Xguest::105:100:a guest:/usr1/guest:/usr/uncw/score
  276. Xscore::105:100:a guest:/usr1/guest:/usr/uncw/score
  277. Xwhipkey:HinSCYmbORBjk:116:100:k whipkey:/usr1/whipkey:
  278. Xsmithh:7g3ZmER5p4epA:123:100:H.F. Smith,CH 200-E,3953819,,:/usr1/smithh:
  279. Xnorris:8F42zTTbXo3Ak:125:100:f r norris,264,3953301,,:/usr1/norris:/bin/csh
  280. Xjudges:8HrGYoJq3fxdQ:453:453:the judges,,,,:/usr2/judges:/bin/csh
  281. Xteam1:mrCEcc.F8UocI:478:478:team1:/usr1/team1:/bin/csh
  282. Xteam2:6DsWELtbNWOLg:479:479:team2:/usr1/team2:/bin/csh
  283. Xteam3:BRc8uYjDHRO6.:480:480:team3:/usr2/team3:/bin/csh
  284. Xteam4:Icegxkv..vEcQ:481:481:team4:/usr2/team4:/bin/csh
  285. Xteam5:BjLwNCM7HePeU:482:482:team5:/usr2/team5:/bin/csh
  286. Xteam6:Oo3fEvH61VKeo:483:483:team6:/usr2/team6:
  287. Xteam7:k0isgx3nuFK1Q:484:484:team7:/usr3/team7:
  288. Xteam8:h35xJdDATkW5Y:485:485:team8:/usr3/team8:
  289. Xteam9:foTUAMb51CRDM:486:486:team9:/usr1/team9:
  290. Xteam10:b/vzhtWaiNAJA:487:487:team10:/usr1/team10:
  291. Xteam11:6LmSPFh9PpBDw:488:488:team11:/usr3/team11:
  292. Xteam12:omg0gx1Lw2lr2:489:489:team12:/usr3/team12:/bin/csh
  293. Xteam13:FlwviGdBAAXFE:490:490:team13:/usr3/team13:/bin/csh
  294. Xteam14:kYWLsTLpfiLFg:491:491:team14:/usr3/team14:/bin/csh
  295. END_OF_FILE
  296. if test 1863 -ne `wc -c <'passwd'`; then
  297.     echo shar: \"'passwd'\" unpacked with wrong size!
  298. fi
  299. # end of 'passwd'
  300. fi
  301. if test -f 'prob1.c' -a "${1}" != "-c" ; then 
  302.   echo shar: Will not clobber existing file \"'prob1.c'\"
  303. else
  304. echo shar: Extracting \"'prob1.c'\" \(829 characters\)
  305. sed "s/^X//" >'prob1.c' <<'END_OF_FILE'
  306. Xmain()
  307. X{
  308. X    int *left, *right, *doub;
  309. X    int l,m, i=0,j,k;
  310. X    int nd=0;
  311. X    char *malloc();
  312. Xleft=(int *)malloc(500*sizeof(int));
  313. Xright=(int *)malloc(500*sizeof(int));
  314. Xdoub=(int *)malloc(500*sizeof(int));
  315. X
  316. X    for(i=0;i<500;i++)doub[i]=0;
  317. X    i=0;
  318. X    while( scanf("%d%d",&j,&k)==2)
  319. X    if(j>=0 && k>=0){left[i]=j; right[i]=k; i++;}
  320. X    else break;
  321. X    i--;
  322. X    for (j=0;j<=i;j++)
  323. X    {
  324. X        k=left[j];
  325. X        for(m=0;m<=i;m++)if(k==right[m]){doub[nd++]=k;break;}
  326. X    }
  327. X    if(nd){
  328. X/*        for(i=0;i<nd;i++)if(doub[i])printf("%d\n",doub[i]);*/
  329. X
  330. X        if(nd>=2){
  331. X            for(i=0;i<nd-1;i++)
  332. X            for(j=i+1;j<nd;j++)
  333. X            if(doub[i]>doub[j]){k=doub[i];doub[i]=doub[j];doub[j]=k;}
  334. X            else {}
  335. X        }else printf("%d\n",doub[0]);
  336. X
  337. X    }else{}
  338. X    doub[nd]= -1;
  339. X/*        for(i=0;i<nd;i++)if(doub[i])
  340. Xprintf("%d\n",doub[i]);
  341. X*/
  342. X
  343. Xk= -1;
  344. X
  345. X    for(i=0;i<nd;i++)if(doub[i]!=doub[i+1])
  346. Xprintf("%d\n",doub[i]);
  347. X
  348. X    return 0;
  349. X}
  350. END_OF_FILE
  351. if test 829 -ne `wc -c <'prob1.c'`; then
  352.     echo shar: \"'prob1.c'\" unpacked with wrong size!
  353. fi
  354. # end of 'prob1.c'
  355. fi
  356. if test -f 'prob13.c' -a "${1}" != "-c" ; then 
  357.   echo shar: Will not clobber existing file \"'prob13.c'\"
  358. else
  359. echo shar: Extracting \"'prob13.c'\" \(2166 characters\)
  360. sed "s/^X//" >'prob13.c' <<'END_OF_FILE'
  361. Xmain(){
  362. X    int oldop,mask,flag;
  363. X#define newline '\n'
  364. X#define null '\0'
  365. X    /*
  366. XFrom norris Fri Nov 11 11:06:03 1988
  367. XBinary-binary
  368. X
  369. X    Mathematicians refer to addition and subtraction as binary
  370. Xoperations.  Since computer scientists like to take things much
  371. Xfarther than they were intended, you are going to write a
  372. Xbinary binary calculator.
  373. X    This calculator program will accept infix expressions involving
  374. Xonly + and - and unsigned binary integers.  No parentheses or
  375. Xother operations will be present.  You must compute the value
  376. Xof the expression and display the result in binary.  Negative
  377. Xresults should be printed with a leading minus sign.
  378. X    Data considerations:
  379. X      Input will consist of an unspecified number of expressions,
  380. X   one per line; end-of-file will indicate the end of data. Each
  381. X   expression will contain no leading or embedded blanks.  No
  382. X   expression will contain more than 80 characters.  The
  383. X   expression values are to be computed left-to-right.  No
  384. X   number or intermediate value will require more than 15 bits
  385. X   of precision.  Output should start in column 1 of the 
  386. X   output file, one result per line, with no leading zeroes.
  387. X
  388. XExample:
  389. X   the input expression:   110+11-1+100
  390. X   results in the output
  391. X1100
  392. X
  393. X   the input expression:   1100-11000+111-10
  394. X   results in the output
  395. X-111
  396. X*/
  397. X    char line[90];
  398. X    int sum,n;
  399. X    char *p;
  400. X    char *gets();
  401. X    while(  gets(line)==line  ){
  402. X        p=line;
  403. X        n=0;
  404. X        for(p=line,n=0,sum=0,oldop='+';;p++) {
  405. X            switch(*p){
  406. X            case '-':
  407. X            case '+':
  408. X                if(oldop=='+')sum += n; 
  409. X                else sum -=n; 
  410. X                n=0; 
  411. X                oldop= *p;
  412. X                break;
  413. X            case '0': 
  414. X                n= n* 2; 
  415. X                break;
  416. X            case '1': 
  417. X                n= n*2+1; 
  418. X                break;
  419. X            case newline:
  420. X            case 0:
  421. X                if(oldop=='+')sum += n; 
  422. X                else sum -=n; 
  423. X                goto out;
  424. X/*                n=0; */
  425. X/*                oldop= *p;*/
  426. X                break;
  427. X            default: 
  428. X                ;
  429. X            }
  430. X        }
  431. Xout: /*printf("%d\n",sum);*/
  432. X        ;
  433. X        if(sum==0){
  434. X            putchar('0');
  435. X            putchar(newline);
  436. X            continue;
  437. X        }
  438. X        if(sum<0){
  439. X            putchar('-'); 
  440. X            sum = - sum;
  441. X        }
  442. X        for(mask=0100000, flag=0; mask; mask >>=1){
  443. X
  444. X            if(sum & mask ){
  445. X                putchar('1');
  446. X                flag=1;
  447. X            } else if(flag)putchar('0');
  448. X        }
  449. X        putchar(newline);
  450. X
  451. X    }/*endwhile gets*/
  452. X}/*end main*/
  453. END_OF_FILE
  454. if test 2166 -ne `wc -c <'prob13.c'`; then
  455.     echo shar: \"'prob13.c'\" unpacked with wrong size!
  456. fi
  457. # end of 'prob13.c'
  458. fi
  459. if test -f 'prob13.txt' -a "${1}" != "-c" ; then 
  460.   echo shar: Will not clobber existing file \"'prob13.txt'\"
  461. else
  462. echo shar: Extracting \"'prob13.txt'\" \(1400 characters\)
  463. sed "s/^X//" >'prob13.txt' <<'END_OF_FILE'
  464. XProblem 13: Binary-binary.
  465. X
  466. X    Mathematicians refer to addition and subtraction as binary
  467. Xoperations.  Since computer scientists like to take things much
  468. Xfarther than they were intended, you are going to write a
  469. Xbinary binary calculator.
  470. X    This calculator program will accept infix expressions involving
  471. Xonly + and - and unsigned binary integers.  No parentheses or
  472. Xother operations will be present.  You must compute the value
  473. Xof the expression and display the result in binary.  Negative
  474. Xresults should be printed with a leading minus sign.
  475. X    Data considerations:
  476. X      Input will consist of an unspecified number of expressions,
  477. X   one per line; end-of-file will indicate the end of data. Each
  478. X   expression may contain leading or embedded blanks; however, no
  479. X   number will contain embedded blanks.
  480. X   A totally blank line should evoke an output of '0'.
  481. X   No expression will contain more than 80 characters.  The
  482. X   expression values are to be computed left-to-right.  No
  483. X   number or intermediate value will require more than 15 bits
  484. X   of precision.  Output should start in column 1 of the 
  485. X   output file, one result per line, with no leading zeroes.
  486. X
  487. XExample:
  488. X   the input expression:   110+11- 1  +100
  489. X   results in the output
  490. X1100
  491. X
  492. X   the input expression:      1100     - 11000+111-10
  493. X   results in the output
  494. X-111
  495. X
  496. X   the input expression: <a blank line>
  497. X   results in the output
  498. X0
  499. END_OF_FILE
  500. if test 1400 -ne `wc -c <'prob13.txt'`; then
  501.     echo shar: \"'prob13.txt'\" unpacked with wrong size!
  502. fi
  503. # end of 'prob13.txt'
  504. fi
  505. if test -f 'prob14.c' -a "${1}" != "-c" ; then 
  506.   echo shar: Will not clobber existing file \"'prob14.c'\"
  507. else
  508. echo shar: Extracting \"'prob14.c'\" \(1054 characters\)
  509. sed "s/^X//" >'prob14.c' <<'END_OF_FILE'
  510. Xmain(){
  511. X    int a[4];
  512. X    int numfnd = -1;
  513. X    int this, found[10000];
  514. X    int t;
  515. X    int p,q,r,s,i,j,k,l,n;
  516. X    for(i=0;i<10;i++)
  517. X        for(j=0;j<10;j++)if(i==j)continue;
  518. X        else
  519. X            for(k=0;k<10;k++)
  520. X                for(l=0;l<10;l++)if(k==l)continue;
  521. X                else
  522. X                {
  523. X                    p=i*10+j;
  524. X                    q=k*10+l;
  525. X
  526. X                    r=j*10+i;
  527. X                    s=l*10+k;
  528. X                    if(p==r || p==s ||q==r||q==s)continue;
  529. X                    else
  530. X                        if((n=p*q) == r*s){
  531. X                            int i,j;
  532. X                            /*bingo*/
  533. X                            a[0]=p;
  534. X                            a[1]=q;
  535. X                            a[2]=r;
  536. X                            a[3]=s;
  537. Xxxx:
  538. X                            for(i=0;i<4;i++)for(j=i;j<4;j++)if(a[i]>a[j]){
  539. X                                t=a[i];
  540. X                                a[i]=a[j];
  541. X                                a[j]=t;
  542. X                                goto xxx;
  543. X                            }
  544. X                            /*printf("%d %d %d %d %d  " ,p,q,r,s,n);*/
  545. X                            this=a[0]*1000000+a[1]*10000+a[2]*100+a[3];
  546. X                            if(numfnd== -1){
  547. X                                found[++numfnd]=this;
  548. X                                printf("%d %d\n",a[0],n);
  549. X                                continue;
  550. X                            }
  551. X                            else{
  552. X                                t=0;
  553. X                                for(i=0;i<=numfnd;i++)if(found[i]==this)t=1;
  554. X                            }
  555. X                            if(!t)
  556. X                            {
  557. X                                found[++numfnd]=this; 
  558. X                                printf("%d %d\n",a[0],n);
  559. X                            }
  560. X                            else /*putchar('\n')*/ ;
  561. X                        }
  562. X                }
  563. X
  564. X
  565. X}
  566. END_OF_FILE
  567. if test 1054 -ne `wc -c <'prob14.c'`; then
  568.     echo shar: \"'prob14.c'\" unpacked with wrong size!
  569. fi
  570. # end of 'prob14.c'
  571. fi
  572. if test -f 'prob14.txt' -a "${1}" != "-c" ; then 
  573.   echo shar: Will not clobber existing file \"'prob14.txt'\"
  574. else
  575. echo shar: Extracting \"'prob14.txt'\" \(1119 characters\)
  576. sed "s/^X//" >'prob14.txt' <<'END_OF_FILE'
  577. XProblem 14: Reverse products.
  578. X
  579. X
  580. XThe product 64 * 69 = 4416, and so also is the product 46 * 96 with the
  581. Xdigits reversed in both numbers.  Write a program that prints all such
  582. Xpairs of two-digit numbers with this property. For purposes of this
  583. Xproblem, numbers less than 10 are to be considered two-digit numbers.
  584. XHowever, exclude the following:  numbers having the same two digits 
  585. X(e.g., 77), pairs where one of the original numbers is just the 
  586. Xreverse of the other (e.g., 46 and 64), and any DUPLICATE sets of 
  587. Xnumbers (i.e., the foursome 46, 64, 69, 96 should be found just once).
  588. XThe output for this problem should consist of lines,
  589. Xeach with two values:  p = the smallest element of a foursome, and
  590. Xq = the corresponding product value.  Thus, the line for this example
  591. Xcase would contain:  46   4416.  Moreover, the lines should be 
  592. Xordered by values of p, and then by values of q in case of 
  593. Xrepetitions of p values.
  594. X
  595. XThere is no input file for this problem.
  596. X
  597. XSample output:
  598. X1 20      <this is tricky: comes from 01*20 == 10*02 >
  599. X1 30
  600. X ...
  601. X ...
  602. X34 2924
  603. X ...
  604. X
  605. XHint: there are fifty output lines in a correct answer.
  606. END_OF_FILE
  607. if test 1119 -ne `wc -c <'prob14.txt'`; then
  608.     echo shar: \"'prob14.txt'\" unpacked with wrong size!
  609. fi
  610. # end of 'prob14.txt'
  611. fi
  612. if test -f 'prob15.txt' -a "${1}" != "-c" ; then 
  613.   echo shar: Will not clobber existing file \"'prob15.txt'\"
  614. else
  615. echo shar: Extracting \"'prob15.txt'\" \(1064 characters\)
  616. sed "s/^X//" >'prob15.txt' <<'END_OF_FILE'
  617. XProblem 15: Circular execution.
  618. X
  619. X
  620. XYou and your friends are suddenly rounded up into a circle.  You are told
  621. Xthat, starting from the head of the circle, THEY will count to M, execute
  622. Xthat Mth person, close the circle, and repeat this process until just one
  623. Xperson is left to escape.  Given that there are N persons and that the
  624. Xrule is to execute every Mth person, you need to decide which position
  625. Xto take in the circle if you are to remain alive.
  626. X
  627. XWrite a program that reads and computes, for four pairs of (M,N) values.
  628. XFor each pair, as your program executes (literally!), have it print out the
  629. Xidentity of each person as he is eliminated.  For example, with M = 7 and
  630. XN = 11, the output would be:  7   3  11   9   8  10   2   6   1   4  5
  631. X(showing 5 (the last guy in the list) surviving).
  632. X
  633. XThere will be exactly four M,N pairs in the input datafile, two per line.
  634. XM and N will each be less than or equal to 20.
  635. XSuch as:
  636. X7 11
  637. X9 13
  638. X13 15
  639. X7 14
  640. X
  641. XNote that there is NO requirement that M be less than N.
  642. X
  643. XBe careful that your output consists of exactly four lines.
  644. END_OF_FILE
  645. if test 1064 -ne `wc -c <'prob15.txt'`; then
  646.     echo shar: \"'prob15.txt'\" unpacked with wrong size!
  647. fi
  648. # end of 'prob15.txt'
  649. fi
  650. if test -f 'prob16.c' -a "${1}" != "-c" ; then 
  651.   echo shar: Will not clobber existing file \"'prob16.c'\"
  652. else
  653. echo shar: Extracting \"'prob16.c'\" \(1273 characters\)
  654. sed "s/^X//" >'prob16.c' <<'END_OF_FILE'
  655. Xmain(){
  656. X    int ii,jj,kk,a,b,M,N,i,j,k;
  657. X    int abin,bbin,nbin[200],bin[200][30];
  658. X
  659. X    scanf("%d%d",&M,&N);
  660. X    for(i=1;i<=N;i++){
  661. X        bin[i][1]=i;
  662. X        nbin[i]=1;
  663. X    }
  664. X    for(kk=1;kk<=M;kk++){
  665. X        if(scanf("%d%d",&a,&b)!=2)exit(1);
  666. X        ii=jj=0;
  667. X        for(i=1;i<=N;i++){
  668. X            if(nbin[i]<1)continue;
  669. X            for(j=1;j<=nbin[i];j++)
  670. X                if(bin[i][j]==a){
  671. X                    ii=i;
  672. X                    jj=j;
  673. X                }
  674. X        }
  675. X        if(ii==0||jj==0){
  676. X            printf("oops a=%d b=%d ii=%d jj=%d i=%d j=%d nbin[ii]=%d\n"
  677. X                ,a,b,ii,jj,i,j,nbin[ii]);
  678. X            exit(2);
  679. X        }
  680. X        /*bin[ii][jj]=0;*/
  681. X        abin=ii;
  682. X        ii=jj=0;
  683. X        for(i=1;i<=N;i++){
  684. X            if(nbin[i]<1)continue;
  685. X            for(j=1;j<=nbin[i];j++)
  686. X                if(bin[i][j]==b){
  687. X                    ii=i;
  688. X                    jj=j;
  689. X                    break;
  690. X                }
  691. X        }
  692. X        if(ii==0||jj==0){
  693. X            printf("oops ii=%d jj=%d i=%d j=%d nbin[ii]=%d\n"
  694. X            ,ii,jj,i,j,nbin[ii]);
  695. X            exit(3);
  696. X        }
  697. X        bbin=ii;
  698. X        for(j=1;j<=nbin[abin];j++)bin[bbin][++nbin[bbin]]=bin[abin][j];
  699. X        nbin[abin]=0;
  700. X    }
  701. X    for(i=1;i<=N;i++)
  702. X    {
  703. X        k=nbin[i];
  704. X        if(k<1)continue;
  705. X        if(k>=2){
  706. X            int l,m;
  707. X            for(l=1;l<k;l++)for(m=l+1;m<=k;m++)if(bin[i][l]>bin[i][m]){
  708. X                int t; 
  709. X                t=bin[i][l]; 
  710. X                bin[i][l]=bin[i][m]; 
  711. X                bin[i][m]=t;
  712. X            }
  713. X        }
  714. X    }
  715. X    for(i=1;i<=N;i++)
  716. X    for(kk=1;kk<=N;kk++)
  717. X    if(nbin[kk]<1)continue; else{
  718. X        if(bin[kk][1]==i){
  719. X            for(j=1;j<=nbin[kk];j++) printf(" %d ",bin[kk][j]);
  720. X            puts("");
  721. X
  722. X        }
  723. X        }
  724. X
  725. X}
  726. END_OF_FILE
  727. if test 1273 -ne `wc -c <'prob16.c'`; then
  728.     echo shar: \"'prob16.c'\" unpacked with wrong size!
  729. fi
  730. # end of 'prob16.c'
  731. fi
  732. if test -f 'prob16.txt' -a "${1}" != "-c" ; then 
  733.   echo shar: Will not clobber existing file \"'prob16.txt'\"
  734. else
  735. echo shar: Extracting \"'prob16.txt'\" \(1059 characters\)
  736. sed "s/^X//" >'prob16.txt' <<'END_OF_FILE'
  737. XProblem 16: Equivalence classes.
  738. X
  739. X
  740. XSuppose that we have a set of N objects {a[i]}.  We are also given M statements
  741. Xof the form a[i]  == a[j]  .  Let us assume that the objects have been mapped into
  742. Xthe integers 1 .. N by some manner.  For example, with N = 19 and M = 16, we
  743. Xmight have the following objects and relationships:
  744. X       18 = 12        16 = 14         8 = 18        16 =  6
  745. X        6 = 10         9 =  1        17 =  4        16 = 17
  746. X        8 =  2         3 = 13         9 = 11         3 =  8
  747. X       11 =  5         7 = 19         3 =  9        19 = 15
  748. XWrite a program that reads M and N, followed by the M pairings i = j,
  749. Xwith i and j both in the range 1 .. N.  Your program should compute which
  750. Xobjects fall into which classes of equivalent objects, and should then
  751. Xprint out these classes, as follows:  objects sorted within each class,
  752. Xand classes printed in order of their first members.  Thus, for the example
  753. Xabove, the output would be:
  754. X          1   2   3   5   8   9  11  12  13  18
  755. X          4   6  10  14  16  17
  756. X          7  15  19
  757. X
  758. END_OF_FILE
  759. if test 1059 -ne `wc -c <'prob16.txt'`; then
  760.     echo shar: \"'prob16.txt'\" unpacked with wrong size!
  761. fi
  762. # end of 'prob16.txt'
  763. fi
  764. if test -f 'prob17.c' -a "${1}" != "-c" ; then 
  765.   echo shar: Will not clobber existing file \"'prob17.c'\"
  766. else
  767. echo shar: Extracting \"'prob17.c'\" \(787 characters\)
  768. sed "s/^X//" >'prob17.c' <<'END_OF_FILE'
  769. X#include <stdio.h>
  770. Xmain(){
  771. X    int z,s,x[4],y[4],tx,ty,xi,yi,abig,area();
  772. X    char *p;
  773. X    int t=0,i,k;
  774. X    while( scanf("%d%d",&x[1],&y[1]) == 2){
  775. X    scanf("%d%d",&x[2],&y[2]);
  776. X    scanf("%d%d",&x[3],&y[3]);
  777. X    t++;
  778. X    for(k=1;k<=7;k++){
  779. X    scanf("%d%d",&tx,&ty);
  780. X    abig=area(x,y);
  781. X    s=(int)0;
  782. X    for(i=1;i<=3;i++){
  783. X        xi=x[i];
  784. X        x[i]=tx;
  785. X        yi=y[i];
  786. X        y[i]=ty;
  787. X        s +=area(x,y);
  788. X        x[i]=xi;
  789. X        y[i]=yi;
  790. X
  791. X    }
  792. X    z=s-abig;
  793. X    if(z<0)z= -z;
  794. X    if(z==0){
  795. X/*    fprintf(stderr,"yes\n");*/
  796. X    p="inside";}
  797. X    else {
  798. X/*    fprintf(stderr,"no\n");*/
  799. X    p="outside";}
  800. X    printf("%d %d is %s triangle %d\n",(int)(tx),(int)(ty),p,t);
  801. X/*    fprintf(stderr,"\n");*/
  802. X    }
  803. X    }
  804. X}
  805. Xint area(x,y)
  806. Xint x[],y[];
  807. X{
  808. X    int z;
  809. X    z= (x[1]*y[2]-x[1]*y[3]+x[2]*y[3]-x[2]*y[1]+x[3]*y[1]-x[3]*y[2]);
  810. X/*    z= z ;*/
  811. X    if(z<0)z = -z;
  812. X/*    fprintf(stderr,"area=%d ",z);*/
  813. X    return z;
  814. X}
  815. END_OF_FILE
  816. if test 787 -ne `wc -c <'prob17.c'`; then
  817.     echo shar: \"'prob17.c'\" unpacked with wrong size!
  818. fi
  819. # end of 'prob17.c'
  820. fi
  821. if test -f 'prob17.txt' -a "${1}" != "-c" ; then 
  822.   echo shar: Will not clobber existing file \"'prob17.txt'\"
  823. else
  824. echo shar: Extracting \"'prob17.txt'\" \(936 characters\)
  825. sed "s/^X//" >'prob17.txt' <<'END_OF_FILE'
  826. XProblem 17:  Point inside triangle.
  827. X
  828. XWhen is a point (s,t) inside a triangle with vertices (x1, y1), 
  829. X(x2, y2), (x3, y3)??  For this problem, the input will contain 20 
  830. Xlines containing coordinate pairs:
  831. X     three lines with coordinates of three vertices of first triangle
  832. X     seven lines, each with coordinates of a point to be tested therein
  833. X     three lines with coordinates of three vertices of second triangle
  834. X     seven lines, each with coordinates of a point to be tested therein
  835. X
  836. XFor example, if the first five lines of input were
  837. X     3   2
  838. X     6  10
  839. X    15   7
  840. X     5   7
  841. X    14   6
  842. Xthe corresponding output would be
  843. X     5   7  is  inside triangle  1
  844. X    14   6  is outside triangle  1
  845. X
  846. XSpacing of the output is not important, but you must have the words
  847. X"is", "inside" or "outside", and "triangle" in your output, just as
  848. Xin the example.
  849. X
  850. XThe vertices of the triangle, and the test point, are guaranteed to
  851. Xbe integers.
  852. X
  853. END_OF_FILE
  854. if test 936 -ne `wc -c <'prob17.txt'`; then
  855.     echo shar: \"'prob17.txt'\" unpacked with wrong size!
  856. fi
  857. # end of 'prob17.txt'
  858. fi
  859. if test -f 'prob2.txt' -a "${1}" != "-c" ; then 
  860.   echo shar: Will not clobber existing file \"'prob2.txt'\"
  861. else
  862. echo shar: Extracting \"'prob2.txt'\" \(1204 characters\)
  863. sed "s/^X//" >'prob2.txt' <<'END_OF_FILE'
  864. XProblem 2: Character count.
  865. X
  866. XFor all the lines in a file, count the occurrences of the
  867. Xvarious characters in that file.
  868. X
  869. XThe input file will be a text file of unknown length, but
  870. Xwith each line guaranteed to be less than 80 characters long.
  871. X
  872. XThe input file may contain tabs (ascii octal 011), blanks,
  873. Xand all the printable characters, as well as newlines.
  874. X
  875. XDo not attempt to count newlines; only tabs, blanks, and printable
  876. Xcharacters.
  877. X
  878. XYour output should consist of two integers per line. The leftmost
  879. Xshould be the ascii character printed in decimal form, the rightmost
  880. Xshould be the count of the character.
  881. X
  882. XBUT: do not output zero-counts.  That is: do not print any line
  883. Xfor which the count is zero.
  884. X
  885. XExample:
  886. Xtime for all
  887. X    good men to
  888. Xcome to the aid of 
  889. X
  890. X(note that the word "good" is preceded by a tab-character).
  891. X
  892. XShould produce:
  893. X    9    1                  <this is the tab>
  894. X   32    8                  <this is "blank">
  895. X   97    2                  <this is "a">
  896. X   99    1                  <etc., and of course, you don't
  897. X  100    2                   print these comments>
  898. X  101    4
  899. X  102    2
  900. X  103    1
  901. X  104    1
  902. X  105    2
  903. X  108    2
  904. X  109    3
  905. X  110    1
  906. X  111    7
  907. X  114    1
  908. X  116    4
  909. END_OF_FILE
  910. if test 1204 -ne `wc -c <'prob2.txt'`; then
  911.     echo shar: \"'prob2.txt'\" unpacked with wrong size!
  912. fi
  913. # end of 'prob2.txt'
  914. fi
  915. if test -f 'prob4.txt' -a "${1}" != "-c" ; then 
  916.   echo shar: Will not clobber existing file \"'prob4.txt'\"
  917. else
  918. echo shar: Extracting \"'prob4.txt'\" \(864 characters\)
  919. sed "s/^X//" >'prob4.txt' <<'END_OF_FILE'
  920. XProblem 4: Print odds and evens side-by-side.
  921. X
  922. XThe input file will consist of some positive integers.  The number
  923. Xof integers will be less than thirty.  Each integer will be
  924. Xgreater than or equal to one.  The last line of the input file
  925. Xwill contain a negative number, for use as a sentinel. There will
  926. Xbe one integer per line, left justified, beginning in column 1.
  927. X
  928. XThe output is to consist of lines of the form:
  929. Xodd number  even number
  930. X
  931. Xwhere the numbers are those from the input file, in the order in
  932. Xwhich they occurred.  
  933. X
  934. XIf there are fewer odd numbers than even numbers, pad with -1 .
  935. XIf there are fewer even numbers than odd numbers, pad with -1 .
  936. X
  937. XDo not output a line consisting of -1 -1 .
  938. X
  939. XExample input file:
  940. X9
  941. X8
  942. X12
  943. X13
  944. X2
  945. X4
  946. X-1
  947. X
  948. XThe output should be:
  949. X9 8
  950. X13 12
  951. X-1 2
  952. X-1 4
  953. X
  954. XAnother example file:
  955. X9
  956. X11
  957. X13
  958. X2
  959. X4
  960. X7
  961. X-1
  962. X
  963. XThe output should be
  964. X9 2
  965. X11 4
  966. X13 -1
  967. X7 -1
  968. END_OF_FILE
  969. if test 864 -ne `wc -c <'prob4.txt'`; then
  970.     echo shar: \"'prob4.txt'\" unpacked with wrong size!
  971. fi
  972. # end of 'prob4.txt'
  973. fi
  974. if test -f 'prob5.txt' -a "${1}" != "-c" ; then 
  975.   echo shar: Will not clobber existing file \"'prob5.txt'\"
  976. else
  977. echo shar: Extracting \"'prob5.txt'\" \(1051 characters\)
  978. sed "s/^X//" >'prob5.txt' <<'END_OF_FILE'
  979. XProblem 5: count the number of words in a text file.
  980. X
  981. XThe input file will consist of some number of lines.
  982. XThere will be only lowercase letters and blanks (and of course, 
  983. Xnewlines) in the input file.  (I.e., no tabs).
  984. XEach line will have zero or more non-blank strings separated
  985. Xby one or more blanks.  Leading blanks are permitted in the input file.
  986. XA "word" is defined as a "string which does not contain a blank".
  987. XYour program should produce exactly as many lines as there are
  988. Xlines in the input file.  Your output should be the integer number
  989. Xrepresenting the number of "words" on the corresponding input line.
  990. X
  991. XExample:  if the input file consists of exactly six lines:
  992. Xnow is the time
  993. Xfor all
  994. X thirty days hath
  995. X   september
  996. X
  997. X   testing testing cqcqcq de k4xe
  998. X
  999. XThen your output would be
  1000. X4
  1001. X2
  1002. X3
  1003. X1
  1004. X0
  1005. X5
  1006. X            <this line is not part of your output>
  1007. XPay particular attention to the fact that a blank line should 
  1008. Xproduce a zero-count in your output file.  To emphasize:
  1009. XYou should produce some output for each line of input, even if
  1010. Xit is totally blank.
  1011. END_OF_FILE
  1012. if test 1051 -ne `wc -c <'prob5.txt'`; then
  1013.     echo shar: \"'prob5.txt'\" unpacked with wrong size!
  1014. fi
  1015. # end of 'prob5.txt'
  1016. fi
  1017. if test -f 'prob6.txt' -a "${1}" != "-c" ; then 
  1018.   echo shar: Will not clobber existing file \"'prob6.txt'\"
  1019. else
  1020. echo shar: Extracting \"'prob6.txt'\" \(988 characters\)
  1021. sed "s/^X//" >'prob6.txt' <<'END_OF_FILE'
  1022. XProblem 6: Count the relationships.
  1023. X
  1024. XThe input file will contain an unknown number of lines each
  1025. Xhaving four positive integers.  The last line will be
  1026. X -1 -1 -1 -1
  1027. X
  1028. XDo not output anything for the last line; it's there for use
  1029. Xas a sentinel.
  1030. X
  1031. XThe numbers on each line are guaranteed to be distinct; that is, 
  1032. Xno number will appear more than once in the quartet of numbers.
  1033. X
  1034. XFor each line, count the number of times a smaller number appears
  1035. Xto the left of a larger number, and also count the number of times
  1036. Xa larger number appears to the left of a smaller number;
  1037. Xfor example, if the four numbers are
  1038. X 7 9 27 23
  1039. Xthe "lessthan" count is 5, because 7<9, 7<27, 7<23, 9<27, 9<23, 
  1040. Xbut 27>23; the "greaterthan" count is 1, because 27>23.
  1041. X
  1042. XYour output should be: the original four numbers followed by
  1043. Xthe lessthan-count and the greaterthan-count all on one line.
  1044. X
  1045. XEach input line should generate one output line.
  1046. X
  1047. XFor example, your output line for the above input line would be:
  1048. X 7 9 27 23 5 1
  1049. X
  1050. END_OF_FILE
  1051. if test 988 -ne `wc -c <'prob6.txt'`; then
  1052.     echo shar: \"'prob6.txt'\" unpacked with wrong size!
  1053. fi
  1054. # end of 'prob6.txt'
  1055. fi
  1056. if test -f 'sb.c' -a "${1}" != "-c" ; then 
  1057.   echo shar: Will not clobber existing file \"'sb.c'\"
  1058. else
  1059. echo shar: Extracting \"'sb.c'\" \(1719 characters\)
  1060. sed "s/^X//" >'sb.c' <<'END_OF_FILE'
  1061. X#include <stdio.h>
  1062. X#define newline '\n'
  1063. X#define blank ' '
  1064. X#define tab '\t'
  1065. X#define indent {myputs(line);ilev++;goto lbl;}
  1066. X#define undent {ilev--;myputs(line);goto lbl;}
  1067. Xint ilev = 0;
  1068. Xmain(argc,argv) char **argv;
  1069. X{
  1070. X    char line[512], *a;
  1071. X    int i;
  1072. X
  1073. X    while(gets(line)==line){
  1074. X    a=line;
  1075. X    while(*a){if(*a==newline)*a=0; a++;}
  1076. X        if(endsin(line,"then")==0){
  1077. X            indent        }
  1078. X        if(endsin(line,"else")==0){
  1079. X            
  1080. X            ilev--; myputs(line); ilev++;goto lbl;
  1081. X            }
  1082. X        if(endsin(line,"fi")==0){
  1083. X            undent        }
  1084. X        if(endsin(line,"done")==0){
  1085. X            undent        }
  1086. X        if(endsin(line,"do")==0){
  1087. X            indent        }
  1088. X        if(begins(line,"case")==0){
  1089. X            indent        }
  1090. X        if(endsin(line,"esac")==0){
  1091. X            undent        }
  1092. X    myputs(line);
  1093. Xlbl: ;
  1094. X    }
  1095. X}
  1096. Xmyputs(p)char *p;
  1097. X{
  1098. X    int i;
  1099. X    while(*p==blank ||*p==tab)p++;
  1100. X    if(ilev>0)for(i=1;i<=ilev;i++)printf("   ");
  1101. X/*    printf("%d",ilev);*/
  1102. X    puts(p);
  1103. X}
  1104. X
  1105. Xendsin(a,b)
  1106. Xchar *a, *b;
  1107. X{
  1108. X    char *aa;
  1109. X    int i;
  1110. X    aa=a;
  1111. X    while(*aa==blank || *aa==tab)aa++;
  1112. X    if(strlen(a)<strlen(b))return -1;
  1113. X    a = a +strlen(a)-strlen(b);
  1114. X    i= kindex(a,b);
  1115. X    if(strlen(aa)==strlen(b))return i;
  1116. X    a--;
  1117. X    if(*a==tab||*a==';'||*a==blank)return i; else return -1;
  1118. X/*    printf("in endsin, a=%s b=%s returning %d\n",a,b,i);*/
  1119. X/*    fflush(stdout);*/
  1120. X/*    return i;*/
  1121. X
  1122. X}
  1123. X    
  1124. X
  1125. X
  1126. X
  1127. X
  1128. Xbegins(a,b)
  1129. Xchar *a, *b;
  1130. X{
  1131. X    int i;
  1132. X    while(*a==blank || *a==tab)a++;
  1133. X    return kindex(a,b);
  1134. X
  1135. X}
  1136. X    
  1137. X
  1138. X
  1139. X
  1140. Xkindex(s,t) 
  1141. Xchar s[],t[];
  1142. X{
  1143. X    int c,i,j,k;
  1144. X    c=s[0];
  1145. X    if(c==0){return -1;
  1146. X/*        i=puts("in kindex ... dummy, s[0] is zero");j=i;*/
  1147. X/*        puts(t);*/
  1148. X/*        if(i==j)exit(1);*/
  1149. X        }
  1150. X    c=t[0];
  1151. X    if(c==0){return -1;
  1152. X/*    i=puts("in kindex ... dummy, t[0] is zero");j=i;*/
  1153. X/*        puts(s);*/
  1154. X/*        if(j==i)exit(1);*/
  1155. X        }
  1156. X    for(i=0;s[i] !='\0'; i++){
  1157. X        for(j=i,k=0;t[k] !='\0' && s[j]==t[k];j++,k++)
  1158. X                ;
  1159. X        if(t[k]=='\0')return (i);
  1160. X    }
  1161. X        return(-1);
  1162. X} 
  1163. END_OF_FILE
  1164. if test 1719 -ne `wc -c <'sb.c'`; then
  1165.     echo shar: \"'sb.c'\" unpacked with wrong size!
  1166. fi
  1167. # end of 'sb.c'
  1168. fi
  1169. if test -f 'start' -a "${1}" != "-c" ; then 
  1170.   echo shar: Will not clobber existing file \"'start'\"
  1171. else
  1172. echo shar: Extracting \"'start'\" \(1067 characters\)
  1173. sed "s/^X//" >'start' <<'END_OF_FILE'
  1174. X
  1175. X#! /bin/sh 
  1176. X
  1177. X#judges mailbox
  1178. XMAIL=$MAIL
  1179. X
  1180. X#a public dir where score lives
  1181. X#(the scoreboard should be local an only readable by judges,
  1182. X# cause "score should be setuid judges)
  1183. XLOCAL=/usr/contest
  1184. X
  1185. X#four hours:
  1186. XLENGTH=14400
  1187. X
  1188. Xcd $HOME
  1189. Xrm -f /tmp/prob*.txt
  1190. X
  1191. X
  1192. Xrm -f t[0-9]*[0-9]*
  1193. Xrm -f keep/*
  1194. Xrm -f subdir/*
  1195. X
  1196. X#version:21
  1197. Xecho "21">xxxx
  1198. X/bin/cp /dev/null listofteams
  1199. X
  1200. Xwhile :
  1201. Xdo
  1202. Xread teamno
  1203. Xcase $teamno in
  1204. X    "") echo null team number;exit;;
  1205. X    -1)break;
  1206. Xesac
  1207. Xecho team$teamno>>listofteams
  1208. Xread cat
  1209. Xread name
  1210. X
  1211. X
  1212. X    echo $teamno $cat $name >>xxxx
  1213. X    echo $teamno $cat $name
  1214. X
  1215. X
  1216. Xdone
  1217. Xecho "-1 -1 xx">>xxxx
  1218. X#change the following line to y for a live start
  1219. Xzork=y
  1220. Xcase $zork in
  1221. X    y)
  1222. X    for i in 1 2 3 4 5 6 13 14 15 16 17 18
  1223. X    do
  1224. X    /bin/cp prob$i.txt /tmp
  1225. X    done ;;
  1226. Xesac
  1227. Xchmod og+r /tmp/*.txt
  1228. X
  1229. X/bin/cp scoreboard scoreboard.old
  1230. Xseconds=`${LOCAL}/seconds`
  1231. Xecho $seconds >> xxxx
  1232. Xecho $seconds > starttime
  1233. Xecho endtime = $endtime
  1234. Xendtime=`expr $seconds '+' ${LENGTH}`
  1235. Xecho endtime = $endtime
  1236. Xecho $endtime > endtime
  1237. X/bin/cp xxxx scoreboard
  1238. Xchmod og-rwx scoreboard
  1239. X
  1240. X
  1241. X${LOCAL}/score
  1242. Xn mal
  1243. Xn ${MAIL}
  1244. END_OF_FILE
  1245. if test 1067 -ne `wc -c <'start'`; then
  1246.     echo shar: \"'start'\" unpacked with wrong size!
  1247. fi
  1248. chmod +x 'start'
  1249. # end of 'start'
  1250. fi
  1251. echo shar: End of archive 2 \(of 3\).
  1252. cp /dev/null ark2isdone
  1253. MISSING=""
  1254. for I in 1 2 3 ; do
  1255.     if test ! -f ark${I}isdone ; then
  1256.     MISSING="${MISSING} ${I}"
  1257.     fi
  1258. done
  1259. if test "${MISSING}" = "" ; then
  1260.     echo You have unpacked all 3 archives.
  1261.     rm -f ark[1-9]isdone
  1262. else
  1263.     echo You still need to unpack the following archives:
  1264.     echo "        " ${MISSING}
  1265. fi
  1266. ##  End of shell archive.
  1267. exit 0
  1268.  
  1269.